<%@page import="cn.easybuy.service.Product_categoryService"%>
<%@page import="cn.easybuy.service.impl.Product_categoryServiceimpl"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>分类列表</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link type="text/css" rel="stylesheet" href="statics/css/style.css" />
	
	
	<script type="text/javascript" src="/EasyBuy/statics/js/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="/EasyBuy/statics/js/menu.js"></script>
	
	<script type="text/javascript" src="/EasyBuy/statics/js/select.js"></script>
  </head>
  
  <body>
  	<%@ include file="../../common/header.jsp" %>
	<%@ include file="../../common/backendHeader.jsp" %>
	
	<c:choose>
		<c:when test="${empty applicationScope.type }">
			<% 	request.getRequestDispatcher("../../UserServlet?opr=type&href=ProductCategoryList&href1=productCategory").forward(request, response); %>
		</c:when>
		<c:otherwise>
			<c:if test="${applicationScope.type==1 }">
  				<%@ include file="../../common/sideMamber.jsp" %> 
			</c:if>
			<c:if test="${applicationScope.type==0 }">
				<%@ include file="../../common/sideUser.jsp" %> 
			</c:if>
		</c:otherwise>
	 </c:choose>
	 
			<div class="m_right">
				<p></p>
				<div class="mem_tit">分类列表</div>
				<form action="" method="post" id="form">
				<p style="padding-left:880px"><input type="submit" value="添加分类"  id="add" name="add"></p>
				<table border="0" class="order_tab" id="order_tab"
					style="width:930px; text-align:center; margin-bottom:30px;"
					cellspacing="0" cellpadding="0">
				</table>
				</form>
			</div>
    <%@ include file="../../common/footer.jsp" %>
<script type="text/javascript"
		src="/EasyBuy/statics/js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript">
    	$(document).ready(function(){
    		$("#add").click(function(){
    			$("#form").attr("action","CommodityInformationServlet?opr=productCategoryAddInfo");
    		});
    	
    		//选择商品分页
  		function selectAll(currPageNotransmit){	
  			var ur;
  			if(currPageNotransmit==""||currPageNotransmit==null||currPageNotransmit.length==0){
  				ur="opr=productCategory";
  			}else{
  				ur="opr=productCategory&pageIndex="+currPageNotransmit;
  			}
  			$.getJSON("CommodityInformationServlet",ur,selectCallBack);
  		}
  		//回调函数
  		function selectCallBack(data){
  			$("#order_tab").html("");
  			$("#order_tab").append("<tr>"+
						"<td width='10%'>选择</td>"+
						"<td width='25%'>分类名称</td>"+
						"<td width='25%'>分类级别</td>"+
						"<td width='20%'>父级分类</td>"+
						"<td width='20%'>操作</td>"+
					"</tr>");
  			for ( var i = 0; i < data.categorylist.length; i++) {
    				var s = data.categorylist[i];
					$("#order_tab").append("<tr><td><input type='radio' /></td>"+
					"<td>"+s.name

				+"</td><td>"+s.type_name+"</td><td>"+s.parentName

				+"</td><td><a class='shan' name='"+s.id+"' title='"+s.type+"'>删除</a></td></tr>");
			}
			$("#order_tab").append("<tr><td colspan='6'><a class='shou'>首页</a><a class='shang'>上一页</a><a class='xia'>下一页</a><a class='mo'>尾页</a></td></tr>");
  			$(".shou").click(function(){//首页
  				selectAll();
  			});
  			$(".shang").click(function(){//上一页
  				selectAll(data.currPageNo-1);
  			});
  			$(".xia").click(function(){//下一页
  				selectAll(data.currPageNo+1);
  			});
  			$(".mo").click(function(){//最后一页
  				selectAll(data.totalCount);
  			});
			$(".shan").click(function(){
				var str=confirm("确定要删除该分类么？");
  				if(str==true){
  					var id=$(this).attr("name");
  					var level=$(this).attr("title");
  					$.getJSON("CommodityInformationServlet","opr=productCategoryDel&id="+id+"&level="+level,callBack);
  					function callBack(data){
  						if(data=="success"){
  							alert("删除成功！");
  							selectAll();
  						}else if(data=="error"){
  							alert("删除失败！");
  							selectAll();
  						}else if(data=="have"){
  							alert("该分类下有商品，不能删除！");
  							selectAll();
  						}
  					}
  				}else{
  					alert("已经取消删除！");
  					selectAll();
  				}
			});
  		};
  		
  		selectAll();
  		});
    </script>
  </body>
</html>
					